package com.ruoyi.web.controller.student;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.BaseBehaviormanagementLog;
import com.ruoyi.service.IBaseBehaviormanagementLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 行为管理Controller
 * 
 * @author ruoyi
 * @date 2025-05-28
 */
@RestController
@RequestMapping("/system/operationlog")
public class BaseBehaviormanagementLogController extends BaseController
{
    @Autowired
    private IBaseBehaviormanagementLogService baseBehaviormanagementLogService;

    /**
     * 查询行为管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BaseBehaviormanagementLog baseBehaviormanagementLog)
    {
        startPage();
        List<BaseBehaviormanagementLog> list = baseBehaviormanagementLogService.selectBaseBehaviormanagementLogList(baseBehaviormanagementLog);
        return getDataTable(list);
    }

    /**
     * 导出行为管理列表
     */
    @Log(title = "行为管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseBehaviormanagementLog baseBehaviormanagementLog)
    {
        List<BaseBehaviormanagementLog> list = baseBehaviormanagementLogService.selectBaseBehaviormanagementLogList(baseBehaviormanagementLog);
        ExcelUtil<BaseBehaviormanagementLog> util = new ExcelUtil<BaseBehaviormanagementLog>(BaseBehaviormanagementLog.class);
        util.exportExcel(response, list, "行为管理数据");
    }

    /**
     * 获取行为管理详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(baseBehaviormanagementLogService.selectBaseBehaviormanagementLogById(id));
    }

    /**
     * 新增行为管理
     */
    @Log(title = "行为管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseBehaviormanagementLog baseBehaviormanagementLog)
    {
        Long userid = getUserId();
        LoginUser loginUser = getLoginUser();
        SysUser currentUser = loginUser.getUser();
        baseBehaviormanagementLog.setUserName(currentUser.getNickName());
        baseBehaviormanagementLog.setUserId(userid);
        String time = DateUtils.getTime();
        baseBehaviormanagementLog.setOperationTime(time);
        return toAjax(baseBehaviormanagementLogService.insertBaseBehaviormanagementLog(baseBehaviormanagementLog));
    }

    /**
     * 修改行为管理
     */
    @Log(title = "行为管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseBehaviormanagementLog baseBehaviormanagementLog)
    {
        return toAjax(baseBehaviormanagementLogService.updateBaseBehaviormanagementLog(baseBehaviormanagementLog));
    }

    /**
     * 删除行为管理
     */
    @Log(title = "行为管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseBehaviormanagementLogService.deleteBaseBehaviormanagementLogByIds(ids));
    }
}
